<?php
include_once ('../global.php');
$page=isset($_GET['page'])?$_GET['page']:1;
$mt_id=isset($_GET['mt_id'])?$_GET['mt_id']:4579;
$name=isset($_GET['name'])?safe_replace($_GET['name']):"";
$page_size=isset($_GET['page_size'])?$_GET['page_size']:20;
$start=($page-1)*$page_size;

//4578 资格赛  4400 大师赛  4579 锦标赛
$where=" WHERE  mp.mp_club=567  ";
$where.=" and mp.mp_match='{$mt_id}'";


if($name){
    $where.=" and p.pl_cn_name='{$name}'";
}
 $sql = "SELECT * FROM match_player mp left join `player` p on mp.mp_player_id=p.pl_id   {$where} limit {$start},{$page_size}";
$list= $db->SelectSQL($sql);
foreach ($list as &$val){
    $sql = "SELECT * FROM bmw_player_video where pl_id='{$val["pl_id"]}' and mt_id='{$mt_id}'";
    $info= $db->SelectSQL($sql);
    $val['video']=$info?$info[0]['video']:"";
    $sql = "SELECT * FROM `bmw_member_sign` WHERE user_id = '{$val["pl_id"]}' and mt_id='{$mt_id}' ";
    $res = $db->SelectSQL($sql);
    $val['sign_img']=$res?("https://mapp.scoringchina.com/bmwjunior/mobile/uploads/".$res[0]['sign_img']):"";

}
$sql_count = "SELECT count(*) as count FROM `match_player` mp {$where}";
$info= $db->SelectSQL($sql_count);
$total_count=$info?$info[0]['count']:0;
$total_page=ceil($total_count/$page_size);

//统计

$sql = "SELECT * FROM match_player mp left join `player` p on mp.mp_player_id=p.pl_id {$where}";
$list_a= $db->SelectSQL($sql);
$signed=$no_sign=0;//已签到 未签到
$nan_a=$nv_a=$nan_b=$nv_b=$nan_c=$nv_c=0;//队员的签到详情
$photoed=$videoed=0;//已上传头像 已上传视频

//pl_sex =0 女 =1 男
foreach ($list_a as $v){


    //已签到 未签订
    $sql = "SELECT * FROM `bmw_member_sign` WHERE user_id = '{$v["pl_id"]}' and mt_id='{$mt_id}' ";
    $res = $db->SelectSQL($sql);
    if($res[0]['sign_img']){
        $signed++;

        //详情
        $mp_class=$v['mp_class'];
        $sql = "SELECT * FROM gp_manage   WHERE id='{$mp_class}' and mt_id='{$mt_id}' and club_id=567";
        $res = $db->SelectSQL($sql);
        $group_name=$res[0]['name'];
        if($v['pl_sex']==1){//男
            if (strpos($group_name, "A") !== false) {
                $nan_a++;
            }else if (strpos($group_name, "B") !== false) {
                $nan_b++;
            }else if (strpos($group_name, "C") !== false) {
                $nan_c++;
            }else{
                $nan_a++;
            }
        }
        if($v['pl_sex']==0){//女
            if (strpos($group_name, "A") !== false) {
                $nv_a++;
            }else if (strpos($group_name, "B") !== false) {
                $nv_b++;
            }else if (strpos($group_name, "C") !== false) {
                $nv_c++;
            }else{
                $nv_a++;
            }
        }
    }else{
        $no_sign++;
    }


    //头像
    $pl_photo=$v['pl_photo'];
    if($pl_photo){
        $photoed++;
    }

    //视频
    $sql = "SELECT * FROM bmw_player_video where pl_id='{$v["pl_id"]}' and mt_id='{$mt_id}'";
    $info= $db->SelectSQL($sql);
    if($info[0]['video']){
        $videoed++;
    }


}


?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/assets/store/i/favicon.ico"/>
    <meta name="apple-mobile-web-app-title" content=""/>
    <link rel="stylesheet" href="css/mydata/amazeui.min.css"/>
    <link rel="stylesheet" href="css/mydata/app.css"/>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_783249_t6knt0guzo.css">
    <script src="css/mydata/jquery.min.js"></script>
    <script src="//at.alicdn.com/t/font_783249_e5yrsf08rap.js"></script>
    <style>

        .ordertime,.ordercount  {
            cursor: pointer;
        }


        .arror0 {
        }

        .arror1 {
            background-image: url("/assets/store/img/arrow-down.png");
            background-repeat: no-repeat;
            background-size: 5px 10px;
            background-position: right 5px center;
            padding-right: 10px !important;
        }

        .arror2 {
            background-image: url("/assets/store/img/arrow-up.png");
            background-repeat: no-repeat;
            background-size: 5px 10px;
            background-position: right 5px center;
            padding-right: 10px !important;
        }
        .getall_option {
            display: inline-block;
            margin-left: 20px;
        }

        .getall_option li {
            border-radius: 10px;
            display: inline-block;
            padding: 5px 10px;
            border: 1px solid rgba(0, 0, 0, 0.1);
            cursor: pointer;
        }

        /*.getall_option li:first-child {*/
        /*    border-radius: 5px 0 0 5px*/
        /*}*/

        /*.getall_option li:last-child {*/
        /*    border-radius: 0 5px 5px 0;*/
        /*    margin-left: -4px;*/
        /*}*/

        .getall_option li.active {
            background-color: #0b76ac;
            color: white;
        }

    </style>
</head>

<body data-type="">
<div class="am-g tpl-g">



    <!-- 内容区域 start -->
    <div class="tpl-content-wrapper <?= empty($second) ? 'no-sidebar-second' : '' ?>">

        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <ul class="getall_option">
                                <li <?php if ($mt_id == 4578):echo 'class="active"'; endif; ?>>资格赛</li>
                                <li <?php if ($mt_id == 4400):echo 'class="active"'; endif; ?>>大师赛</li>
                                <li <?php if ($mt_id == 4579):echo 'class="active"'; endif; ?>>锦标赛</li>
                            </ul>
                        </div>
                        <div style="display: inline-block;">已签到：<span style="font-weight: bold"><?php echo $signed;?></span></div>&nbsp; <div style="display: inline-block;">未签到：<span style="font-weight: bold"><?php echo $no_sign;?></span> </div>

                        &nbsp; <div style="display: inline-block;">已上传头像人数：<span style="font-weight: bold"><?php echo $photoed;?></span> </div>&nbsp; <div style="display: inline-block;">已上传视频人数：<span style="font-weight: bold"><?php echo $videoed;?></span> </div>
                        <br/> <div style="display: inline-block;">男子A组：<span style="font-weight: bold"><?php echo $nan_a;?></span> </div>&nbsp; <div style="display: inline-block;">女子A组：<span style="font-weight: bold"><?php echo $nv_a;?></span> </div>
                        &nbsp; <div style="display: inline-block;">男子B组：<span style="font-weight: bold"><?php echo $nan_b;?> </span></div>&nbsp; <div style="display: inline-block;">女子B组：<span style="font-weight: bold"><?php echo $nv_b;?></span> </div>
                        &nbsp; <div style="display: inline-block;">男子C组：<span style="font-weight: bold"><?php echo $nan_c;?></span> </div>&nbsp; <div style="display: inline-block;">女子C组：<span style="font-weight: bold"><?php echo $nv_c;?> </span></div>
                        <div class="am-btn-group am-btn-group-xs  am-fr">
                            <input id="name" style="width: 200px;border:1px solid;height:30px;" placeholder="搜索参赛球员"
                                   value="<?php echo $name;?>"
                                   type="text">
                            <div class="am-vertical-align-middle">
                                <button type="submit" style="font-size: 1rem" onclick="jump()"
                                        class="j-submit am-btn am-btn-secondary">搜索
                                </button>
                            </div>
                        </div>
                        <form id="my-form" class="am-form tpl-form-line-form" method="post">

                            <div class="am-scrollable-horizontal am-u-sm-12">
                                <table width="100%" class="am-table am-table-compact am-table-striped
                         tpl-table-black am-text-nowrap">
                                    <thead>
                                    <tr>
                                        <th >参赛球员</th>
                                        <th >签名</th>
                                        <th >视频</th>
                                        <th >操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    $uuids_str="";
                                    ?>
                                    <?php if($list){ ?>
                                        <?php foreach ($list as $item){ ?>
                                            <tr class="itemline">
                                                <td class="am-text-middle"><?php
                                                    echo $item['pl_cn_name'];

                                                    ?>
                                                </td>
                                                <td class="am-text-middle">
                                                    <?php if($item['sign_img']){ ?>
                                                        <a href="<?php echo $item['sign_img'];?>" target="_blank">点击查看</a>
                                                    <?php }else{ ?>
                                                        未签名
                                                    <?php } ?>
                                                </td>
                                                <td class="am-text-middle">
                                                    <?php if($item['video']){ ?>
                                                        <a href="<?php echo $item['video'];?>" target="_blank">点击查看</a>
                                                    <?php }else{ ?>
                                                    未上传
                                                    <?php } ?>
                                                </td>
                                                <td class="am-text-middle">
                                                    <input onchange="get_name(<?php echo $item['mp_player_id'];?>,<?php echo $mt_id;?>)" type="file" style="display: none;" class="uploadFile" id="uploadFile<?php echo $item['mp_player_id'];?><?php echo $mt_id;?>"/>
                                                    <input class="btn btn-primary radius" type="button" value="上传比赛视频"  onclick="$('#uploadFile<?php echo $item['mp_player_id'];?><?php echo $mt_id;?>').click()"/>


                                                </td>



                                            </tr>
                                        <?php } ?>
                                    <?php }else{ ?>
                                        <tr>
                                            <td colspan="12" class="am-text-center">暂无记录</td>
                                        </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </div>

                            <div class="am-u-lg-12 am-cf">

                                <div class="am-fr">
                                    <ul class="pagination">

                                        <?php if($page==1) {?>
                                            <li class="disabled"><span>«</span></li>
                                        <?php } ?>
                                        <?php for ($i = 1; $i <= $total_page; $i++) { ?>

                                            <?php if($page==$i) {?>
                                                <li class="active"><span><?php echo $i;?></span></li>
                                            <?php }else {?>
                                                <li><a href="/bmwjunior/mobile/player.php?page=<?php echo $i;?>&mt_id=<?php echo $mt_id;?>"><?php echo $i;?></a></li>

                                            <?php } ?>

                                        <?php } ?>
                                        <?php if($page<$total_page) {?>
                                            <li><a href="/bmwjunior/mobile/player.php?page=<?php echo $page+1;?>&mt_id=<?php echo $mt_id;?>">»</a></li>
                                        <?php } ?>
                                    </ul>

                                </div>
                                <div class="am-fr pagination-total am-margin-right">
                                    <div class="am-vertical-align-middle">总记录：<?= $total_count ?></div>
                                </div>
                            </div>
                        </form>


                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 内容区域 end -->

</div>
<script>

    $('.getall_option li').click(function () {
        $('.getall_option li').removeClass('active');
        $(this).addClass('active');
        jump();
    });

    function jump() {
        var urls='';
        if ($('.getall_option li.active').index() == 1) {
            urls += '/bmwjunior/mobile/player.php?mt_id=4400';
        }else  if ($('.getall_option li.active').index() == 2) {
            urls += '/bmwjunior/mobile/player.php?mt_id=4579';
        }else {
            urls += '/bmwjunior/mobile/player.php?mt_id=4578';
        }
        var name=$("#name").val();
        if(name !=""){
            urls+="&name="+name
        }
        window.location.href = urls
    }

    $(function () {
        //按钮的点击事件
        // $('.btn').click(function () {
        //     //触发file的点击事件
        //
        // });

    });

    function get_name(user_id,mt_id){
        var file = $('#uploadFile'+user_id+mt_id)[0].files[0],
            form = new FormData();
        form.append("file", file);
        form.append("user_id", user_id);
        form.append("mt_id", mt_id);
        $.ajax({
            type: 'post',
            url:"uploadoss.php",
            data: form,
            contentType: false,
            processData: false,
            dataType: 'json',
            success:function(req){
                //请求成功时处理
                if (req.code == 1) {
                   alert("上传成功");
                   window.location.reload();
                }else{
                    alert("上传失败重新上传！");
                }
            },
        });
    }
</script>
</body>

</html>